//
//  GXShopBGViewController.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/3.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXShopBGViewController.h"
#import "ImagePickerTool.h"
#import "OrderAndUploadPhotoMananger.h"
@interface GXShopBGViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *backImageView;
@property (nonatomic,copy) NSString * imageStr;
@property (nonatomic,assign)BOOL imageType;
@end

@implementation GXShopBGViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"店铺背景图";
    self.view.backgroundColor = kGlobalbgColor;
    [self requestBackImageData];
}
- (void)requestBackImageData
{
    [ShopAuthenticationManager selectShopBackImageWithStoreID:StoreId success:^(id responseObject) {
        if (responseObject) {
            self.imageStr = responseObject[@"describa"];
            NSString * urlStr = [NSString stringWithFormat:@"%@/%@",kBaseURLIMAGE,self.imageStr];
            [self.backImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"placeholder_cover2"]];
        }
    } fail:^(id responseObject) {
    }];
}
- (IBAction)uploadPhotoBtn:(id)sender {
    [[ImagePickerTool sharePicker] showImagePicker:self allowEdit:YES complete:^(id param) {
        [OrderAndUploadPhotoMananger uploadPhotoToServerFromImage:param fileName:BackImage success:^(id responseObject) {
            if (responseObject) {
                self.backImageView.image = param;
                self.imageStr = responseObject[@"describa"];
                self.imageType = YES;
            }
        } fail:^(id responseObject) {
        
        }];
    }];
}

- (IBAction)pressSaveBtn:(id)sender {
    if (!self.imageType) {
        [SVProgressHUD showErrorWithStatus:@"未修改"];
        return;
    }
    [ShopAuthenticationManager changeShopBackImageWithStoreID:StoreId backImage:self.imageStr success:^(id responseObject) {
        if (responseObject) {
            if (self.changeBackImageBlock) {
                self.changeBackImageBlock(YES);
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    } fail:^(id responseObject) {
    }];
    
}

@end
